Skip to content

Allow valid targets alongside empty directories - #22177

Open
nightcityblade wants to merge 2 commits into
python:masterfrom
nightcityblade:fix/issue-22173
Open

nightcityblade wants to merge 2 commits into
python:masterfrom
nightcityblade:fix/issue-22173

Conversation

@nightcityblade

Copy link
Copy Markdown

Fixes #22173

create_source_list now defers the existing empty-directory error until all explicit targets have been scanned. This lets mypy check valid targets alongside an empty directory while preserving the fatal error when no sources are found.

A regression test covers both the mixed-target and all-empty cases.

Validation:

  • TMPDIR=/tmp .venv/bin/python -m pytest -n0 mypy/test/test_find_sources.py -q (10 passed)
  • .venv/bin/python runtests.py lint (passed)
  • .venv/bin/python runtests.py self (346 source files checked successfully)
  • .venv/bin/python -m mypy .github . against the issue reproduction (success; 1 source file)

AI assistance: Codex helped draft the focused change and test; I reviewed the diff and ran all validation locally.

@github-actions

This comment has been minimized.

@nightcityblade

nightcityblade commented Oct 11, 2026 •

Copy link
Copy Markdown
Author

Fixed the Windows-only test expectation in 7d71289 by accepting both POSIX and drive-prefixed Windows separators. I also folded pre-commit.ci’s import-spacing auto-fix into the authored commit, preserving single-commit history. The focused 10-test suite passed before the formatting-only bot change; the final tree passes Ruff, ruff format, py_compile, and git diff --check. CI is rerunning.

@github-actions

This comment has been minimized.

@Zocker1999NET Zocker1999NET left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm & should fix my issue. thanks for implementing that so fast ❤️

now only a maintainer decision is required for this change

Comment thread mypy/find_sources.py Outdated
mod = os.path.basename(path) if options.scripts_are_modules else None
sources.append(BuildSource(path, mod, None))
if not sources and empty_dirs:
raise InvalidSourceList(f"There are no .py[i] files in directory '{empty_dirs[0]}'")

@Zocker1999NET Zocker1999NET Oct 11, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because multiple dirs can be supplied & the error now only occurs when all dirs are "empty", I would just list all dirs in the error:

Suggested change
raise InvalidSourceList(f"There are no .py[i] files in directory '{empty_dirs[0]}'")
empty_dirs_str = ", ".join(map(repr, empty_dirs))
raise InvalidSourceList(f"There are no .py[i] files in directories: {empty_dirs_str}")

(and then also improve the escaping of the path strings, some Linux users have e.g. ' in their paths xD)

EDIT: This suggestion requires a small adaption on the test, because the message no longer matches because I used the plural directories.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 1ed6ecf. create_source_list now reports every empty directory using repr, so paths containing quotes are escaped unambiguously. The regression covers two empty directories (including a quoted path). Validation passed: TMPDIR=/tmp .venv/bin/python -m pytest -n0 mypy/test/test_find_sources.py -q (10 passed), .venv/bin/python runtests.py lint, and git diff --check.

@nightcityblade

Copy link
Copy Markdown
Author

Thanks for confirming the fix works for your issue and for the approval!

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

scipy-stubs (https://github.com/scipy/scipy-stubs)
- tests/misc/test_submodules_empty.pyi:3: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

empty directory among multiple targets aborts whole check

2 participants